/* ****************************************************************************
 * Author: 671643387
 * Date: 2015/3/23
 * ***************************************************************************/

Ext.define("sggm.controller.ContentLeft", {
    extend: "Ext.app.Controller",
    refs: [{
        ref: "contentLeft",
        selector: "contentLeft"
    }, {
        ref: "contentCenter",
        selector: "contentCenter"
    }],

    init: function() {
        this.control({
            'contentLeft > treepanel': {
                itemclick: this.onClick,
                afterrender: this.cltpAfterRender
            }
        });
    },

    onClick: function(view, record, item, index, event) {
        console.log(record.getPath());
        var center = this.getContentCenter();
        var child = null;
        if (record.get("text") == "GM工具"
            && center.currentView != 'gmPanel') {
            center.removedView[center.currentView] = center.items.get(0);
            center.removeAll();

            child = center.removedView['gmPanel'];
            if (child) {
                console.log("add old gmPanel");
                center.add(child);
            } else {
                console.log("add new gmPanel");
                center.add({xtype:"gmPanel"});
            }
            center.currentView = 'gmPanel';
        }
    },

    cltpAfterRender: function(sender) {
        console.log("AAA");
        sender.selectPath("/root/gmtool");
        this.getContentCenter().add({xtype:"gmPanel"});
        this.getContentCenter().currentView = 'gmPanel';
    }
});